package com.example.chapter05.fragment;

import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.example.chapter05.R;
import com.example.chapter05.bean.Person;

/**
 * A simple {@link Fragment} subclass.
 * Use the  factory method to
 * create an instance of this fragment.
 */
// 1. 创建一个待处理的Fragment
public class BlankFragment1 extends Fragment implements View.OnClickListener {
    private static final String TAG = "BlankFragment1";
    private View root;
    private TextView textView;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        // inflate 解析器
        if (root == null)
            root = inflater.inflate(R.layout.fragment_blank1, container, false);
        textView = root.findViewById(R.id.tv_fragment);
        Button button = root.findViewById(R.id.btn_fragment);
        button.setOnClickListener(this);
        return root;
    }

    @Override
    public void onClick(View view) {
        Bundle bundle = getArguments();
        if (view.getId() == R.id.btn_fragment) {
            textView.setText("I am fine, thank you.");
            if (bundle != null) {
                Person person = (Person) bundle.get("Person");
                if (person != null)
                    textView.setText(person.toString());
            } else
                Log.d("Rain", "bundle为null");
        }
    }

    public BlankFragment1() {
    }


}